package davidlauzon.activerecord.manager;

import java.sql.SQLException;
import java.util.List;

import davidlauzon.activerecord.connection.ConnectionAdapter;
import davidlauzon.activerecord.nodes.DropTableStatement;
import davidlauzon.activerecord.nodes.SqlStatement;
import davidlauzon.activerecord.nodes.Table;


public class DropTableStatementManager extends StatementManager
{
    private DropTableStatement _statement;

    private Table    _table;
    private boolean  _ifExists;

    
    public DropTableStatementManager() {
        super();
    }
    
    public void reset() {
        super.reset();
       _table       = null;
       _ifExists = false;
    }
    
    public DropTableStatementManager table(Table table) {
        _table = table;
        setConnection(    _table.getConnection() );
        setSqlSerializer( _table.getConnection().getSerializer() );
        return this;
    }
    
    public DropTableStatementManager ifExists() {
        _ifExists = true;
        return this;
    }
    
    @Override
    protected SqlStatement buildStatement() {
        _statement = new DropTableStatement();
        _statement.setTable(_table);
        _statement.setIfExists(_ifExists);
        
        return _statement;
    }
    
    public long execute() throws SQLException {
        String sql = this.toSql();
        return getConnection().executeUpdate( sql );
    }
}
